package com.ryskoo.catering.coupondetail.domain;

import com.ryskoo.common.hclconstant.CouponStateEnum;
import com.ryskoo.common.hclconstant.CouponTypeEnum;
import com.ryskoo.framework.core.bean.BasicPO;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 优惠券明细
 *
 * @author BeHappy
 */
@Entity
@Table(name = "cater_coupon_detail")
public class CouponDetailPO extends BasicPO {

    private static final long serialVersionUID = 943607241184463147L;
    /**
     * 卖家uuid
     */
    @Column(name = "vendor_uuid", columnDefinition = "char", length = 32)
    private String vendorUuid;

    /**
     * 会员uuid
     */
    @Column(name = "customer_uuid", columnDefinition = "char", length = 32)
    private String customerUuid;
    
    /**
     * 会员名称
     */
    @Column(name = "customer_name", columnDefinition = "varchar", length = 50)
    private String customerName;

    /**
     * 优惠券uuid
     */
    @Column(name = "coupon_uuid", columnDefinition = "char", length = 32)
    private String couponUuid;

    /**
     * 优惠券号
     */
    @Column(name = "coupon_no", columnDefinition = "varchar", length = 32)
    private String couponNo;


    /**
     * 优惠券名称
     */
    @Column(name = "coupon_name", columnDefinition = "varchar", length = 50)
    private String couponName;

    /**
     * 优惠券类型
     */
    @Column(name = "coupon_type", columnDefinition = "tinyint", length = 2)
    private int couponType;

    /**
     * 面值
     */
    @Column(name = "coupon_price", columnDefinition = "decimal", length = 11, precision = 2)
    private double couponPrice;

    /**
     * 使用条件
     */
    @Column(name = "reach_price", columnDefinition = "decimal", length = 11, precision = 2)
    private double reachPrice;

    /**
     * 状态
     */
    @Column(name = "state", columnDefinition = "tinyint", length = 2)
    private int state;

    /**
     * 有效开始时间
     */
    @Column(name = "start_valid_time", columnDefinition = "char", length = 19)
    private String startValidTime;

    /**
     * 有效结束时间
     */
    @Column(name = "end_valid_time", columnDefinition = "char", length = 19)
    private String endValidTime;

    /**
     * 领取时间
     */
    @Column(name = "receive_time", columnDefinition = "char", length = 19)
    private String receiveTime;

    /**
     * 使用时间
     */
    @Column(name = "use_time", columnDefinition = "char", length = 19)
    private String useTime;

    /**
     * 订单ID
     */
    @Column(name = "order_id", columnDefinition = "varchar", length = 32)
    private String orderId;

    /**
     * 关联商品uuid
     */
    @Column(name = "product_uuid", columnDefinition = "char", length = 32)
    private String productUuid;

    @Transient
    private String productName;

    @Transient
    private String couponTypeName;
    @Transient
    private String stateName;

    public String getVendorUuid() {
        return vendorUuid;
    }

    public void setVendorUuid(String vendorUuid) {
        this.vendorUuid = vendorUuid;
    }

    public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getCustomerUuid() {
        return customerUuid;
    }

    public void setCustomerUuid(String customerUuid) {
        this.customerUuid = customerUuid;
    }

    public String getCouponUuid() {
        return couponUuid;
    }

    public void setCouponUuid(String couponUuid) {
        this.couponUuid = couponUuid;
    }

    public String getCouponNo() {
        return couponNo;
    }

    public void setCouponNo(String couponNo) {
        this.couponNo = couponNo;
    }

    public String getCouponName() {
        return couponName;
    }

    public void setCouponName(String couponName) {
        this.couponName = couponName;
    }

    public int getCouponType() {
        return couponType;
    }

    public void setCouponType(int couponType) {
        this.couponType = couponType;
    }

    public double getCouponPrice() {
        return couponPrice;
    }

    public void setCouponPrice(double couponPrice) {
        this.couponPrice = couponPrice;
    }

    public double getReachPrice() {
        return reachPrice;
    }

    public void setReachPrice(double reachPrice) {
        this.reachPrice = reachPrice;
    }

    public int getState() {
        // 获取当前时间戳
        long nowTimeStamp = new Date().getTime();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String endValidTime = getEndValidTime();
        if(endValidTime.length()==10){
            endValidTime += " 23:59:59";
        }
        try {
            Date endDate = df.parse(endValidTime);
            long endTimeStamp = endDate.getTime();
            if(nowTimeStamp>endTimeStamp){
                this.state = CouponStateEnum.OUT_OF_DATE.getValue();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getStartValidTime() {
        return startValidTime;
    }

    public void setStartValidTime(String startValidTime) {
        this.startValidTime = startValidTime;
    }

    public String getEndValidTime() {
        return endValidTime;
    }

    public void setEndValidTime(String endValidTime) {
        this.endValidTime = endValidTime;
    }

    public String getReceiveTime() {
        return receiveTime;
    }

    public void setReceiveTime(String receiveTime) {
        this.receiveTime = receiveTime;
    }

    public String getUseTime() {
        return useTime;
    }

    public void setUseTime(String useTime) {
        this.useTime = useTime;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getProductUuid() {
        return productUuid;
    }

    public void setProductUuid(String productUuid) {
        this.productUuid = productUuid;
    }

    public String getCouponTypeName() {
        return CouponTypeEnum.getNameByValue(this.couponType);
    }

    public void setCouponTypeName(String couponTypeName) {
        this.couponTypeName = couponTypeName;
    }

    public String getStateName() {
        return CouponStateEnum.getNameByValue(this.state);
    }

    public void setStateName(String stateName) {
        this.stateName = stateName;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }
}
